﻿using UnityEngine;
using System.Collections;
using GameUnit;
public class ThirdCamera : MonoBehaviour
{
    Camera mCamera;
    GameScene curScene;
    Vector3 OffsetPos = new Vector3(0, 20, -50);
    void Start()
    {
        mCamera = GetComponent<Camera>();
        if (mCamera == null)
        {
            mCamera = gameObject.AddComponent<Camera>();
        }
        curScene = Game.Scene.Cur<GameScene>();
    }

    public void Init(Vector3 offsetPos)
    {
        this.OffsetPos = offsetPos;
    }

    public void Update()
    {
        if (curScene.LocalPlayer != null&&curScene.LocalPlayer.MainUnit != null)
        {
            transform.localPosition = curScene.LocalPlayer.MainUnit.transform.position + OffsetPos;
            transform.LookAt(curScene.LocalPlayer.MainUnit.transform);
        }
    }
}
